package 算法.leetcode;

/**
 * @author:谢君臣
 * @Date:2021/5/19-8:31
 * @version:1.0
 * @function:
 */
public class lc03 {
    public static void main(String[] args) {
        System.out.println(findRepeatNumber(new int[]{2, 3, 1, 0, 2, 5, 3}));
    }
    public static int findRepeatNumber(int[] nums) {
        for(int i = 0 ;i<nums.length;i++){
            while(nums[i]!=i){
                if(nums[i]>=nums.length) return -1;
                if(nums[nums[i]]!= nums[i]){
                    int temp = nums[i];
                    nums[i] = nums[nums[i]];
                    nums[temp] = temp;
                }else{
                    return nums[i];
                }
            }
        }
        return 0;
    }
}
